mod user;
mod weibo;

use once_cell::sync::OnceCell;
use sqlx::SqlitePool;
use std::sync::Arc;

pub use user::User;
pub use weibo::Weibo;

static DB: OnceCell<Arc<SqlitePool>> = OnceCell::new();

pub(crate) async fn init_db() -> Result<(), sqlx::Error> {
    let pool = SqlitePool::connect("/home/zeng/pub_db.db").await?;
    DB.set(Arc::new(pool))
        .map_err(|_| sqlx::Error::RowNotFound)?;
    Ok(())
}

pub(crate) fn get_db() -> Arc<SqlitePool> {
    DB.get().expect("DB not initialized").clone()
}
